<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>

</h:head>

<h:body>

	<ui:composition template="/WEB-INF/templates/1000_layout.xhtml">

		<ui:define name="head">
			<title>Purchase Requisition: Edit</title>
		</ui:define>

		<ui:define name="clipboard">
			<h:form id="clipboardForm">
				<ui:include src="/WEB-INF/templates/misc/clipboard.dialog.xhtml">
					<ui:param name="updateDiscard" value="@form :partUnitTable" />
				</ui:include>
			</h:form>
		</ui:define>


		<ui:define name="user_project_list_show">
			<ui:param name="showUserProjectlist" value="false" />
		</ui:define>

		<ui:define name="content">
			<br />
			<p:fieldset id="fsMain"  style="background-color:#FFFFE0">
				<h:form id="prForm">

					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.edit.xhtml">
						<ui:param name="bean"
							value="#{dtEditPurchaseRequisitionView.purchaseRequisition}" />
						<ui:param name="backingBean"
							value="#{dtEditPurchaseRequisitionView}" />
						<ui:param name="updateDirty" value=":prForm:saveBtn" />
					</ui:include>

					<br />

					<!-- buttons OPEN status -->
					<p:commandButton value="Save" id="saveBtn"
						rendered="#{dtEditPurchaseRequisitionView.statusOpen}"
						disabled="#{not dtEditPurchaseRequisitionView.dirty}"
						update=":fsMain :fsAuditTrail"
						action="#{dtEditPurchaseRequisitionView.save}" />
						
					<p:commandButton value="Re-Open" id="reopenBtn" ajax="false"
						rendered="#{dtEditPurchaseRequisitionView.statusPending}"
						update=":fsMain :fsAuditTrail"
						action="#{dtEditPurchaseRequisitionView.reopen}" />

					<p:commandButton value="Submit for Approval"
						rendered="#{dtEditPurchaseRequisitionView.statusOpen}"
						ajax="false"
						disabled="#{dtEditPurchaseRequisitionView.requestEmpty}"
						action="#{dtEditPurchaseRequisitionView.submitForApproval}" />

					<p:commandButton value="Approve"
						rendered="#{dtEditPurchaseRequisitionView.statusPending and dtEditPurchaseRequisitionView.userPrApprover}"
						update=":fsMain :fsAuditTrail"
						action="#{dtEditPurchaseRequisitionView.approve}" />

					<!-- buttons for APPROVED status -->
					<p:commandButton value="Create PO"
						rendered="#{dtEditPurchaseRequisitionView.statusApproved and (userSession.purchaser or userSession.admin)}"
						ajax="false" action="/po/main" />

					<!-- buttons for APPROVED and archived status -->
					<p:commandButton value="Print" ajax="false"
						rendered="#{dtEditPurchaseRequisitionView.statusApproved || dtEditPurchaseRequisitionView.statusArchived}"
						action="#{dtEditPurchaseRequisitionView.printPdf}" />

				</h:form>
				<br />
				<h:form id="reqTableForm">
					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.itemRequest.table.xhtml">
						<ui:param name="backingBean"
							value="#{dtEditPurchaseRequisitionView}" />
					</ui:include>

				</h:form>
				<br/>
				<h:form id="prRemarksForm">

					<p:panelGrid style="width: 100%;">
						<f:facet name="header">
							<p:row>
								<p:column>
									<h:outputText value="Remarks" />
								</p:column>
							</p:row>
						</f:facet>
						<p:row rendered="#{not dtEditPurchaseRequisitionView.remarksEditable}">
							<p:column>
								<pre>
									<h:outputText value="#{dtEditPurchaseRequisitionView.remarks}" />
								</pre>
							</p:column>
						</p:row>
						<p:row rendered="#{dtEditPurchaseRequisitionView.remarksEditable}">
							<p:column>
								<p:inputTextarea value="#{dtEditPurchaseRequisitionView.remarks}"
									style="resize:vertical;width: 100%" rows="3" counter="display"
									maxlength="1024" counterTemplate="{0} characters remaining.">
									<p:ajax event="keyup" update=":prForm:saveBtn"
										listener="#{dtEditPurchaseRequisitionView.markDirty}" />
								</p:inputTextarea>
								<br />
								<h:outputText id="display" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</h:form>

				<h:form id="reqTableDlgForm">
					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.itemRequest.table.dialog.xhtml" />
				</h:form>

				<br/>
				<h:form id="prepForm">
					<table border="0" style="width:100%;">
						<tr>
							<td>PREPARED BY:</td>
							<td style="width:25%;">&nbsp;</td>
							<td style="width:10%; border-left: 1px solid black" rowspan="4">&nbsp;</td>
							<td>APPROVED BY:</td>
							<td style="width:25%;">&nbsp;</td>
						</tr>
						<tr>
							<td>&nbsp;</td>
							<td style="width:25%;">&nbsp;</td>
							<!-- <td style="width:10%;border-left: 1px solid black">&nbsp;</td> -->
							<td></td>
							<td style="width:25%;">&nbsp;</td>
						</tr>
						<tr>
							<td><h:outputText 
								value="#{dtEditPurchaseRequisitionView.purchaseRequisition.owner.displayName}" /></td>
							<td style="width:25%;">&nbsp;</td>
							<!-- <td style="width:10%;border-left: 1px solid black">&nbsp;</td> -->
							<td><h:outputText 
								value="#{dtEditPurchaseRequisitionView.purchaseRequisition.approvedBy.displayName}" /></td>
							<td style="width:25%;">&nbsp;</td>
						</tr>
						<tr>
							<td style="border-top: 1px solid black">SIGNATURE OVER PRINTED NAME</td>
							<td style="width:25%;">&nbsp;</td>
							<!-- <td style="width:10%;border-left: 1px solid black">&nbsp;</td> -->
							<td style="border-top: 1px solid black">SIGNATURE OVER PRINTED NAME</td>
							<td style="width:20%;">&nbsp;</td>
						</tr>
					</table>
				</h:form>

			</p:fieldset>

			<br />

			<p:fieldset id="fsAddItem"
				rendered="#{dtEditPurchaseRequisitionView.statusOpen}"
				legend="Add Item" toggleable="true" toggleSpeed="500"
				collapsed="true">
				<h:form id="partUnitTable"
					rendered="#{dtEditPurchaseRequisitionView.statusOpen}">
					<ui:include src="/WEB-INF/templates/entity/partUnit.table.xhtml">
						<ui:param name="ajaxRowSelectUpdate"
							value=":partUnitForm:partUnitDetail" />
						<ui:param name="ajaxRowSelectOnComplete"
							value="PF('partUnitDialog').show()" />
					</ui:include>
				</h:form>
				<h:form id="partUnitForm"
					rendered="#{dtEditPurchaseRequisitionView.statusOpen}">
					<ui:include
						src="/WEB-INF/templates/entity/partUnit.table.dialog.xhtml" />
				</h:form>
				
				<br/>				
			</p:fieldset>

			<br />
			<p:fieldset id="fsAuditTrail" legend="Audit Trail" toggleable="true"
				toggleSpeed="500" collapsed="true">
				<ui:include
					src="/WEB-INF/templates/entity/purchaseRequisition.audit.xhtml">
					<ui:param name="bean"
						value="#{dtEditPurchaseRequisitionView.purchaseRequisition}" />
				</ui:include>
			</p:fieldset>

		</ui:define>

	</ui:composition>
</h:body>
</html>